package com.gamefx.engine1.consts
{
	import flash.utils.describeType;

	/**
	 * 方向常量表
	 * @author hzf
	 */
	public class DirectionConst
	{
		public static const STOP:uint = 0; //停止（保持上一方向）
		public static const N:uint = 1; //北
		public static const S:uint = 2; //南
		public static const W:uint = 4; //西
		public static const E:uint = 8; //东
		public static const WN:uint = 5; //西北
		public static const WS:uint = 6; //西南
		public static const EN:uint = 9; //东北
		public static const ES:uint = 10; //东南
		public static const RANDOM:uint = 16; //随机方向



		private static var _constantMap:Object;

		/**
		 * 由常量码得到对应的常量名
		 */
		public static function toString(constantValue:uint):String
		{
			var constantName:String;

			if (!_constantMap)
			{
				_constantMap = new Object();

				var description:XMLList = describeType(DirectionConst)..constant.@name;

				for (var i:String in description)
				{
					constantName = description[i].toString();

					_constantMap[DirectionConst[constantName]] = constantName;
				}

			}

			constantName = (_constantMap.hasOwnProperty(constantValue)) ? _constantMap[constantValue] : "undefined";

			return constantName;
		}
	}
}